<?php
 
defined('DSVH') or die('Restricted access');
 
//add chuc danh
function insertphanmem($local){
    mysql_query("insert phan_mem set ten_phan_mem = '".$local['ten_phan_mem']."',
    avatar = '".$local['avatar']."',
    link = '".$local['link']."',
    loai_phan_mem_id = '".$local['loai_phan_mem_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."'",
    dbconnect());
}

function insertloaiphanmem($local){
    mysql_query("insert loai_phan_mem set ten_loai_phan_mem = '".$local['ten_loai_phan_mem']."',
    user_id = '".$local['user_id']."',
    sap_xep = '".$local['sap_xep']."',
    add_date = NOW()",
    dbconnect());
}

function editloaiphanmem($id, $local)
{
    mysql_query("update loai_phan_mem set ten_loai_phan_mem ='".$local['ten_loai_phan_mem']."',
    sap_xep = '".$local['sap_xep']."',
    add_date = NOW() 
    where loai_phan_mem_id = '".(int)$id."'", dbconnect());
}
//list chuc danh
function getListphanmem($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM phan_mem
        left join loai_phan_mem  ON phan_mem.loai_phan_mem_id = loai_phan_mem.loai_phan_mem_id
        order by phan_mem_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    

function getListloaiphanmem($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM loai_phan_mem
        order by loai_phan_mem_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
//ham lay du lieu phong ban theo id
function getphanmem($id)
    {
    $pro = mysql_query("select * from phan_mem where phan_mem_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
function getloaiphanmem($id)
    {
    $pro = mysql_query("select * from loai_phan_mem where loai_phan_mem_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//cap nhat trong muc sua
function editphanmem($id, $local)
{
    mysql_query("update phan_mem set ten_phan_mem ='".$local['ten_phan_mem']."',
    avatar = '".$local['avatar']."',
    link = '".$local['link']."',
    loai_phan_mem_id = '".$local['loai_phan_mem_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."' 
    where phan_mem_id = '".(int)$id."'", dbconnect());
}

// xoa thu muc
function delphanmem($id){
    mysql_query("delete from phan_mem where phan_mem_id ='".(int)$id."'", dbconnect());
}

function total(){
   $result = mysql_query("select * from phan_mem",dbconnect());
    return mysql_num_rows($result);
}

function totalloaiphanmem(){
   $result = mysql_query("select * from loai_phan_mem",dbconnect());
    return mysql_num_rows($result);
}






?>